#ifndef _ST_UTIL_H
#define _ST_UTIL_H

#include <stddef.h>

#define USAGE_STRING \
    "\nUsage: penglai_sign <commands> [options] file...\n"\
    "Commands:\n"\
    "   sign                    Sign the enclave using the private key\n"\
    "   gendata                 Generate enclave signing material to be signed\n"\
    "   catsig                  Generate the signed enclave with the input signature file, the\n"\
    "                           public key and the enclave signing material\n"\
    "   dump                    Dump metadata information for a signed enclave file\n"\
    "Options:\n"\
    "   -enclave                Specify the enclave file to be signed or already signed\n"\
    "                           It is a required option for the four commands\n"\
    "   -key                    Specify the key file\n"\
    "                           It is a required option for \"sign\" and \"catsig\"\n"\
    "   -out                    Specify the output file\n"\
    "                           It is a required option for \"sign\", \"gendata\" and \"catsig\"\n"\
    "   -sig                    Specify the signature file for the enclave signing material\n" \
    "                           It is a required option for \"catsig\"\n"\
    "   -unsigned               Specify the enclave signing material generated by \"gendata\"\n" \
    "                           It is a required option for \"catsig\"\n" \
    "   -dumpfile               Specify a file to dump metadata information (text format)\n" \
    "                           It is a required option for \"dump\"\n" \
    "Run \"penglai_sign -help\" to get this help and exit.\n"

typedef enum _command_mode_t
{
    SIGN = 0,
    GENDATA,
    CATSIG,
    DUMP
} command_mode_t;

void printHex(unsigned char *c, int n);
int get_file_size(const char *filename);
int read_file_to_buf(const char *filename, unsigned char *buffer, size_t bsize, long offset);
int write_data_to_file(const char *filename, const char *modes, unsigned char *buf, size_t bsize, long offset);
int copy_file(const char *source_path, const char *dest_path);

#endif